package com.gomyb.admin.core.shiro.manage;

import org.apache.shiro.session.mgt.SessionManager;
import org.crazycake.shiro.RedisManager;
import org.crazycake.shiro.RedisSessionDAO;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 * 自定义session管理器
 */
@Configuration
public class SessionManage {

    /**
     * 自定义session管理器
     */
    @Bean
    public SessionManager sessionManager(RedisSessionDAO redisSessionDAO) {
        WebSessionManager mySessionManager = new WebSessionManager();
        mySessionManager.setSessionDAO(redisSessionDAO);
        return mySessionManager;
    }

    /**
     * redis session
     */
    @Bean
    public RedisSessionDAO redisSessionDAO(JedisPool jedisPool) {
        RedisSessionDAO redisSessionDAO = new RedisSessionDAO();
        RedisManager redisManager = new RedisManager();
        redisManager.setJedisPool(jedisPool);
        redisSessionDAO.setRedisManager(redisManager);
        return redisSessionDAO;
    }
}
